//
//  RegisterViewController.m
//  Slice
//
//  Created by lanou on 16/6/21.
//  Copyright © 2016年 wangjinchao. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userNameTF;


@property (weak, nonatomic) IBOutlet UITextField *passWordTF;

@property (weak, nonatomic) IBOutlet UITextField *emailAddressTF;

@property (weak, nonatomic) IBOutlet UISegmentedControl *seg;



@end

@implementation RegisterViewController
//注册按钮
- (IBAction)registerAction:(id)sender {
//    获取用户输入的注册信息
    NSDictionary *dataDic = @{@"email":self.emailAddressTF.text,@"passwd":self.passWordTF.text,@"uname":self.userNameTF.text,@"gender":@(self.seg.selectedSegmentIndex)};
//    请求数据
    [RequestTool requsetWithType:POST URLString:REGIST_URL paremeter:dataDic callBack:^(NSData *data, NSError *error) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers  error:nil];
        NSNumber *result = dic[@"result"];
        dispatch_async(dispatch_get_main_queue(), ^{
            if (result.integerValue == 1) {
//       注册成功
                if (self.registerValue) {
                    self.registerValue(self.emailAddressTF.text,self.passWordTF.text);
                }
                [self.navigationController popViewControllerAnimated:YES];
            } else {
//                /注册失败
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册失败" message:dic[@"data"][@"msg"] preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
                [alert addAction:action];
                [self presentViewController:alert animated:YES completion:nil];
            }
        });
}];
    
    
    
    
    
    
}



//返回按钮
- (IBAction)goBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}
@end
